<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use Monolog\Logger;
use Yansongda\Pay\Pay;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {



        //支付容器注入直接app('')调用
        $this->app->singleton('alipay',function (){
            $config = config('pay.alipay');

            $config['notify_url'] = route('payment.alipay.notify');//回调的域名
//            $config['notify_url'] = 'http://requestbin.net/r/w715fmw7';//回调的域名  测试域名
            $config['return_url'] = route('payment.alipay.return');
            //判断当前环境是否为线上环境
            if (app()->environment() !== 'production'){
                $config['mode'] = 'dev';
                $config['log']['level'] = Logger::DEBUG;
            }else{
                $config['log']['level'] = Logger::WARNING;
            }
            //调用yansongda/pay 创建对象
            return Pay::alipay($config);
        });
        $this->app->singleton('wechat_pay', function () {
            $config = config('pay.wechat');

//            $config['notify_url'] = 'http://requestbin.fullcontact.com/[替换成你自己的url]';
            $config['notify_url'] = 'payment.wechat.notify';
            if (app()->environment() !== 'production') {
                $config['log']['level'] = Logger::DEBUG;
            } else {
                $config['log']['level'] = Logger::WARNING;
            }
            // 调用 Yansongda\Pay 来创建一个微信支付对象
            return Pay::wechat($config);
        });
    }
}
